﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using JN.Utility;
using Power.Common;

namespace Power.Config
{
    public partial class SystemSet : DevExpress.XtraEditors.XtraForm
    {
        #region property
        Manager.SystemStatus sysStatus = Manager.SystemStatus.Instance;
        #endregion
        public SystemSet()
        {
            InitializeComponent();
        }

        private void SystemSet_Load(object sender, EventArgs e)
        {
            LoadStatus();
        }
        private void LoadStatus()
        {
            try
            {
                if (sysStatus.IsChangCom)
                {
                    chkChangeCom.Checked = true;
                    chkChangeCom.Text = "开";
                }
                else
                {
                    chkChangeCom.Checked = false;
                    chkChangeCom.Text = "关";
                }
                if (sysStatus.IsStartRead)
                {
                    chkStartRun.Checked = true;
                    chkStartRun.Text = "开";
                }
                else
                {
                    chkStartRun.Checked =false;
                    chkStartRun.Text = "关";
                }
                if (sysStatus.IsIgnoreAlarm)
                {
                    chkIgnoreAlarm.Checked = true;
                    chkIgnoreAlarm.Text = "是";
                }
                else
                {
                    chkIgnoreAlarm.Checked = false;
                    chkIgnoreAlarm.Text = "否";
                }
                spIgnoreCount.Value = sysStatus.IgnoreCount;
            }
            catch (Exception ex)
            {
                Common.Notify.NotifyMessage.Show(ex);
                SystemLogger.Write(ex);
            }
        }

        private void chkStartRun_CheckedChanged(object sender, EventArgs e)
        {
            if (chkStartRun.Checked)
            {
                chkStartRun.Text = "开";
            }
            else
            {
                chkStartRun.Text = "关";
            }
        }

        private void chkChangeCom_CheckedChanged(object sender, EventArgs e)
        {
            if (chkChangeCom.Checked)
            {
                chkChangeCom.Text = "开";
            }
            else
            {
                chkChangeCom.Text = "关";
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            sysStatus.IsStartRead = chkStartRun.Checked;
            sysStatus.IsChangCom = chkStartRun.Checked;
            sysStatus.IsIgnoreAlarm = chkIgnoreAlarm.Checked;
            sysStatus.IgnoreCount = (int)spIgnoreCount.Value;
            Common.Notify.NotifyMessage.Show("提示", "保存成功");
        }

        private void chkIgnoreAlarm_CheckedChanged(object sender, EventArgs e)
        {
            if (chkIgnoreAlarm.Checked)
            {
                chkIgnoreAlarm.Text = "是";
            }
            else
            {
                chkIgnoreAlarm.Text = "否";
            }
        }
    }
}